﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;

using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Reflection;
using Excel = Microsoft.Office.Interop.Excel;
using System.Diagnostics;
using System.IO;
using System.Data.OleDb;

using INSAForManagers.Models;

namespace INSAForManagers
{
    public partial class FormMain : Form
    {
                
        private static ToolStripMenuItem mnuSManagerInfo;

        public static ToolStripMenuItem MnuSManagerInfo
        {
            get { return FormMain.mnuSManagerInfo; }
            set { FormMain.mnuSManagerInfo = value; }
        }
        private static ToolStripMenuItem mnuSACard;
        
        public static ToolStripMenuItem mnuStaticMMain;
        public static ToolStripMenuItem mnuStaticEMain;
        public static ToolStripMenuItem mnuStaticAMain;

        //DataTable For 정보
        private DataTable tblInfo = new DataTable();
        
        public FormMain()
        {
            Control.CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
             
            //메인 폼 환경변수에 등록
            Config.MainForm = this;

            //프로그램 시작 경로 환경변수에 등록
            Config.Path = Application.StartupPath;

            //데이터베이스 연결
            DBUtil.oleConnect();
           


            //다면평가대상자 전체 수
            Config.NumOfTagets = DBUtil.getMTargetCount( );


            Config.EnabledListViewEvent = true;

            //메뉴를 전역변수와 연결
            setStaticMenu();

            //버전 정보를 환경변수에 등록
            Config.Version = DBUtil.getVersion(1);

        }

        private void setStaticMenu()
        {   
            mnuStaticAMain      = mnuAMain;
            mnuSACard           = mnuACard;
        }

        public static  void setMenuDisabled()
        {
         
          
            mnuStaticMMain.Enabled = false;
            mnuStaticEMain.Enabled = false;
            mnuStaticAMain.Enabled = false;
        }

        public static void setMenuEnabled()
        {
         
            
            mnuStaticMMain.Enabled = true;
            mnuStaticEMain.Enabled = true;
            mnuStaticAMain.Enabled = true;
        }

        public static void setMnuSACardEnabled()
        {
            mnuSACard.Enabled = true;
        }

        public static void setMnuSManagerInfoEnabled()
        {
            mnuSManagerInfo.Enabled = true;
        }

        public static void setManagerInfoEnabled()
        {
            mnuSManagerInfo.Enabled = true;
        }


        /*********************************
         * 이벤트 모음
         ********************************/

        private void mnuExit_Click(object sender, EventArgs e)
        {   
            //응용프로그램 종료
            Application.Exit();
        }

        private void FormMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            //MDB 연결 종료            
            DBUtil.oleClose();
        }

        private void FormMain_Load(object sender, EventArgs e)
        {


        }

       
        private void mnuProgramInfo_Click(object sender, EventArgs e)
        {
            Form f = new FormProgramInfo();            
            f.ShowDialog();
        }

        private void mnuACard_Click(object sender, EventArgs e)
        {
            FormACard f = new FormACard();
            f.MdiParent = this;
            f.Show();

            mnuACard.Enabled = false;
        }

        private void lnkVersionCheck_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (MessageBox.Show("업데이트 프로그램 실행을 위해 현재 프로그램을 종료합니다.    \n\n업데이트를 진행하시겠습니까?  ", "확인", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                this.Close();
                Process.Start("InsaUpdateClient.exe", "CheckMode");
            }
        }

    }
}
